<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/gsap.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/ScrollTrigger.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/TextPlugin.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        body {
            /* display: flex;
            align-items: center;
            justify-content: stretch;
            min-height: 100vh; */
        }
        .box1 {
            height: 100vh;
            background-color: #eee;
            display: flex;
            align-items: center;
            justify-content: stretch;
        }
        #t1, #t2 {
          transform: translateX(-100%);
          opacity: 0;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="box1"></div>
        <div class="box1 middle" style="height:10vh; background-color: azure;">
            <div style="padding-left: 15px;">
                <h1 id="t1">GreenSock's TextPlugin<span style="color: orange;"></span></h1>
                <h2 id="t2">Set or animate text in sequence. Reversible too!</h2>
            </div>
        </div>
        <div class="box1"></div>
        
        
      </div>

    <!-- <button id="animate">animate</button> -->
    <script>
        // use a script tag or an external JS file
        document.addEventListener("DOMContentLoaded", (event) => {
            gsap.registerPlugin(ScrollTrigger,TextPlugin)


            const t1 = document.getElementById("t1")
            let timeline1 = gsap.timeline({
                scrollTrigger: {
                    trigger: ".middle",
                    scrub: 1,
                    start: "top 80%",
                    end: "200%",
                    pin: true,
                    markers: true
                }
            })
            timeline1
                .to('#t1', { opacity: 1, x: 0, color: 'purple'}, 0)
                // .to('#t1', {scale: 2,})
                .to('#t1', {scale: 1, color: 'orange'})
                .to('#t2', { opacity: 1, x: 0, color: 'purple'}, 0.2)
                // .to('#t2', {scale: 2,})
                .to('#t2', {scale: 1, color: 'orange'})
                .to('#t1', {})

            // const t2 = document.getElementById("t2")
            // timeline1.to(t2, { opacity: 1, x: 0, color: 'purple'})
            //     .to(t2, {scale: 2,})
            //     .to(t2, {scale: 1, color: 'orange'})
            //     .to(t2, {})

            // let tl2 = gsap.timeline({
            //     scrollTrigger: {
            //         trigger: ".middle",
            //         scrub: 1,
            //         // start: "top 20%",
            //         // top: '10%',
            //         end: "200%",
            //         pin: true,
            //         markers: true
            //     }
            // });
            // const t2 = document.getElementById("t2")
            // tl2.to(t2, { opacity: 1, x: 0, color: 'orange'})
        });
       
       </script>
</body>
</html>